# SDOF Supporting Structure for Validation of Non-structural Damping Models; kN, mm, s
wipe all;


source FMdataSDOF.tcl


wipe;
model BasicBuilder -ndm 2 -ndf 3;	# Define the model builder, ndm=#dimension, ndf=#dofs

source DynamicAnalysisSolver.tcl;

#Define Nodes


node 1 0.0 0.0;
node 2 0.0 0.0;


# assign boundary condidtions 
	# command:  fix nodeID dxFixity dyFixity rzFixity
	# fixity values: 1 = constrained; 0 = unconstrained
	fix 1 1 1 1;
	
# assign mass to node 2
set Mass $M; #in kNs^2/mm
set Negligible 1e-9;
#puts $Mass;

mass 2 $Mass $Mass $Negligible; 

#Define Geometric Transformation
set Transf 1;
geomTransf Linear $Transf; 	# Geometric transformation

#Define Material 
set PI 3.1415;


uniaxialMaterial Elastic 1 100;

uniaxialMaterial SelfCentering 10 $k1 $k2 $sigAct $betaf;		

element zeroLength 1 1 2 -mat 10 1 -dir 1 2 -doRayleigh 1;

equalDOF 1 2 3;



set GMfact 1000.0;				# ground-motion scaling factor
set GMdirection 1;			# ground-motion direction

set DtAnalysis	$dtg;	# time-step Dt for lateral analysis
set TmaxAnalysis	$durs;	# maximum duration of ground-motion analysis -- should be 50*$sec


set omega {}
set freq {}
set perT {}

set lambda [eigen -fullGenLapack 2];

foreach lam $lambda {
	lappend omega [expr sqrt($lam)]
	lappend freq [expr sqrt($lam)/(2*$PI)]
	lappend perT [expr (2*$PI)/sqrt($lam)]
}

set T1 [lindex $perT 0];
set T2 [lindex $perT 1];
puts "T1 = $T1 s";									# display the first mode period in the command window
puts "T2 = $T2 s";	

set xDamp 0.02;					# damping ratio
set MpropSwitch 0.0;
set KcurrSwitch 1.0;
set KcommSwitch 0.0;
set KinitSwitch 0.0;

set alphaM [expr $MpropSwitch*$xDamp*(2*[lindex $omega 0])];	# M-prop. damping; D = alphaM*M
set xbetaKcurr [expr $KcurrSwitch*2.0*$xDamp/([lindex $omega 0])];         		# current-K;      +beatKcurr*KCurrent
set xbetaKcomm [expr $KcommSwitch*2.0*$xDamp/([lindex $omega 0])];   		# last-committed K;   +betaKcomm*KlastCommitt
set xbetaKinit [expr $KinitSwitch*2.0*$xDamp/([lindex $omega 0])];         			# initial-K;     +beatKinit*Kini
# define damping
rayleigh $alphaM $xbetaKcurr $xbetaKinit $xbetaKcomm;  	

set IDloadTag 400;	# for uniformSupport excitation
set IDtimeS 10;     #for ground acceleration time history
# Uniform EXCITATION: acceleration input
		#set inFileH $GMfile.at2
		#ReadRecord $inFileH $outFileH dt nPt;		# call procedure to convert the horizontal ground-motion file
set GMfatt $GMfact;		# data in input file is in m/s2 Unifts -- ACCELERATION TH

timeSeries Path $IDtimeS  -fileTime $FMfilet -filePath $FMfilea -factor  $GMfatt;
pattern UniformExcitation  $IDloadTag  $GMdirection -accel  $IDtimeS;		# create Unifform excitation

# recorder EnvelopeNode -file [format "Results/DispE%d.out" $snumber] -time -node 2 -dof 1 disp;
recorder Node -file "ResultsAttSDOF/AccelT.out" -timeSeries $IDtimeS -time -node 2 -dof 1 accel;
recorder Node -file "ResultsAttSDOF/DispT.out" -time -node 2 -dof 1 disp;
recorder Node -file "ResultsAttSDOF/ForceT.out" -time -node 1 -dof 1 reaction;


puts "Running Floor Motion";

DynamicAnalysisSolver $DtAnalysis $TmaxAnalysis 1.0e-3;

record















